import tkinter as tk

# window = tk.Tk()
# window.title('hello thinter')
# height= window.winfo_screenheight()
# width= window.winfo_screenwidth()
# window.geometry('400x200+%d+%d'%((width-400)/2,(height-200)/2))
# v = tk.IntVar()
# tk.Radiobutton(window, text="男", value=1, variable=v).pack()
# tk.Radiobutton(window, text="女", value=0, variable=v).pack()
# window.mainloop()


# # 获取选中的值
# import tkinter as tk

# def A():
#     param = v.get()
#     print("选中的值",param)
# window = tk.Tk()
# window.title('hello thinter')
# height= window.winfo_screenheight()
# width= window.winfo_screenwidth()
# window.geometry('400x200+%d+%d'%((width-400)/2,(height-200)/2))
# sex = [
#     ('男',1),
#     ('女',0),
#     ('未知',2)
# ]
# v = tk.IntVar()
# for name,value in sex:
#      tk.Radiobutton(window, text=name, value=value, variable=v).pack()
# tk.Button(window,text="获取选中的值",command=A).pack()
# window.mainloop()


# # 默认值

# import tkinter as tk

def A():
    param = v.get()
    print("选中的值",param)
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x200+%d+%d'%((width-400)/2,(height-200)/2))
sex = [
    ('男',1),
    ('女',0),
    ('未知',2)
]
v = tk.IntVar()
v.set(2) #设置默认值
for name,value in sex:
     tk.Radiobutton(window, text=name, value=value, variable=v).pack()
tk.Button(window,text="获取选中的值",command=A).pack()
window.mainloop()
